#include "stdafx.h"
#include "global.h"
#include "bmploader.h"
#include "resource.h"

HRESULT LoadPicture(LPDIRECT3DSURFACE9 *surf, DWORD Resource)
{

	HANDLE hBmp;
	hBmp = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(Resource), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
	BITMAP bm;
	if (hBmp == 0) 
		return FALSE;
	GetObject(hBmp,sizeof(bm), &bm);
	if (*surf) (*surf)->Release();
	GV.pD3Device->CreateOffscreenPlainSurface(
		bm.bmWidth,bm.bmHeight, D3DFMT_A8R8G8B8,
		D3DPOOL_DEFAULT, surf, 0);
	HDC hdcImage = CreateCompatibleDC(0);
	SelectObject(hdcImage,hBmp);
	HDC hdc;
	(*surf)->GetDC(&hdc);
	StretchBlt(
		hdc,0,0, bm.bmWidth, bm.bmHeight, 
		hdcImage, 0,0,bm.bmWidth, bm.bmHeight, 
		SRCCOPY);
	(*surf)->ReleaseDC(hdc);
	DeleteDC(hdcImage);
	DeleteObject(hBmp);
	return S_OK;
}